package com.example.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.swing.plaf.PanelUI;

@Component
@Configuration
public class TopicConfig {

    @Bean
    public TopicExchange topicExchange() {
        TopicExchange topicTestExchange = new TopicExchange("topic_test_exchange");
        return topicTestExchange;
    }

    //四个消息队列
    //湖南，湖北，天气，新闻

    @Bean
    public Queue huNanQueue() {
        return new Queue("huNan.queue");
    }

    @Bean
    public Queue huBeiQueue() {
        return new Queue("huBei.queue");
    }

    @Bean
    public Queue weatherQueue() {
        return new Queue("weather.queue");
    }

    @Bean
    public Queue newsQueue() {
        return new Queue("news.queue");
    }

    //绑定
    //设置规则 # 任意单词 *一个单词
    @Bean
    public Binding huNanBinding() {
        return BindingBuilder.bind(huNanQueue()).to(topicExchange())
                .with("huNan.#");
    }

    @Bean
    public Binding huBeiBinding() {
        return BindingBuilder.bind(huBeiQueue()).to(topicExchange())
                .with("huBei.#");
    }

    @Bean
    public Binding weatherBinding() {
        return BindingBuilder.bind(weatherQueue()).to(topicExchange())
                .with("#.weather");
    }

    @Bean
    public Binding newsBinding() {
        return BindingBuilder.bind(newsQueue()).to(topicExchange())
                .with("#.news");
    }

}
